//
//  BaseViewController.m
//  LittleFairyPoet
//
//  Created by rimi on 15/9/8.
//  Copyright (c) 2015年 周林. All rights reserved.
//

#import "BasicViewController.h"

@interface BasicViewController ()

@end

@implementation BasicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self customBaseNavigationBar];
    [self.view addSubview:self.baseNavigationBar];
    
}
#pragma mark - init
- (void)customBaseNavigationBar {
    self.baseNavigationBar = [[UIView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(0, 0, ORIGIN_WIDTH, 55), NO)];
    self.baseNavigationBar.backgroundColor = [UIColor clearColor];
    [self.baseNavigationBar addSubview:self.leftButton];
    [self.baseNavigationBar addSubview:self.rightButton];
    [self.baseNavigationBar addSubview:self.titleLable];
    [self.leftButton addTarget:self action:@selector(respondsToTabBarLeftButton) forControlEvents:UIControlEventTouchUpInside];
    [self.rightButton addTarget:self action:@selector(respondsToTabBarRightButton:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)initializeAlertControllerWithMessage:(NSString *)msg {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
    [self presentViewController:alertController animated:YES completion:nil];
}
- (void)initAlertControllerDismissWithMessage:(NSString *)msg {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:msg preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alertController animated:YES completion:nil];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [alertController dismissViewControllerAnimated:YES completion:nil];
    });
}
- (void)initializeAlertControllerWithMessage:(NSString *)msg withHandelBlock:(void (^)(UIAlertAction * action))action{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:action]];
    [self presentViewController:alertController animated:YES completion:nil];
}

#pragma mark - respondsToButton
- (void)respondsToTabBarLeftButton {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)respondsToTabBarRightButton:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - getter
- (UIButton *)leftButton {
    if (!_leftButton) {
        _leftButton = ({
            UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = DHFlexibleFrame(CGRectMake(0, 24, 65, 30), YES);
            [button setImage:IMAGE_CONTENT(@"返回.png") forState:UIControlStateNormal];
            button.imageView.contentMode = UIViewContentModeScaleAspectFit;
            button;
        });
    }
    return _leftButton;
}
- (UIButton *)rightButton {
    if (!_rightButton) {
        _rightButton = ({
            UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = DHFlexibleFrame(CGRectMake(255, 24, 65, 30), YES);
            button.imageView.contentMode = UIViewContentModeScaleAspectFit;
            button;
        });
    }
    return _rightButton;
}
- (UILabel *)titleLable {
    if (!_titleLable) {
        _titleLable = ({
            UILabel * lable = [[UILabel alloc]initWithFrame:DHFlexibleFrame(CGRectMake(50, 24, 220, 30), YES)];
            lable.font = [UIFont systemFontOfSize:18];
            lable.textAlignment = NSTextAlignmentCenter;
            lable.numberOfLines = 0;
            lable;
        });
    }
    return _titleLable;
}
@end
